;;;Place pipe break symbol automatically by selecting sides.
;;;(uses PBRK.DWG)
;;;
;;;	AUTHOR: HENRY C. FRANCIS
;;;		425 N. ASHE ST.
;;;		SOUTHERN PINES, NC 28387
;;;              
;;;		All rights reserved without prejudice.
;;;
;;;	Copyright:	6-18-94
;;;	Edited:		6-6-99

(DEFUN C:PBRK ( / clayr bname aname snang omode entla ontla pt1 pt2  ept1a
                     ept1b ept2a ept2b inlay brkp1 brkp2 blkro a b c s k angc
                     perpd)
  (setq old_cmdecho (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (setq old_osmode (getvar "osmode"))
  (setvar "osmode" 0)
  (setq clayr (getvar"clayer")
        bname "pbrk"
        aname (strcat bname ".dwg")
  );setq
    (if (or (findfile aname) bname)
      (while
          (setq entla (nentsel "\nPick left side of pipe "))
      (if
        (and
          (setq ontla (nentsel "\nPick right side of pipe "))
            (= "LINE" (cdr (assoc 0 (entget (car entla)))))
            (= "LINE" (cdr (assoc 0 (entget (car ontla)))))
        );and
          (progn
            (setq pt1 (cadr entla)
                  pt2 (cadr ontla)
                  ept1a (cdr (assoc 10 (entget (car entla))))
                  ept1b (cdr (assoc 11 (entget (car entla))))
                  ept2a (cdr (assoc 10 (entget (car ontla))))
                  ept2b (cdr (assoc 11 (entget (car ontla))))
                  inlay (cdr (assoc 8 (entget (car entla))))
            );setq
            (if (> (distance pt1 ept1a)(distance pt1 ept1b))
              (setq brkp1 ept1b brkp2 ept1a blkro (/(*(angle ept1a ept1b)180.00)pi))
              (setq brkp1 ept1a brkp2 ept1b blkro (/(*(angle ept1b ept1a)180.00)pi))
            );if
            (setq a (distance brkp1 ept2a)
                  b (distance ept2a ept2b)
                  c (distance ept2b brkp1)
                  s (/(+ a b c)2.0)
                  k (sqrt(/(*(- s a)(- s b)(- s c))s))
                  angc (*(atan(/ k (- s c)))2)
                  perpd (*(sin angc)a)
            );setq
            (progn
              (command)
	      (while (wcmatch inlay "*|*")
		(setq inlay (substr inlay 2))
	      )
              (command ".layer" "m" inlay ""
                       ".insert" bname brkp1 perpd perpd blkro
              );command
            );progn
          );progn
        (prompt "\nEntities were not lines or were not both selected. ")
      );if
      );while
      (prompt (strcat "\nBlock " bname " or File " aname " not found! \n"))
    );if
    (setvar "clayer" clayr)
    (setvar "cmdecho" old_cmdecho)
    (setvar "osmode" old_osmode)
    (command)
);defun c:pbrk
